/*
*SharePanel
*chenjie
*2012-5-4
*/
package com.share
{
	import com.btn.ShareBitBtn;
	import com.data.Data;
	import com.player.MainFlvPlayer;
	
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	import flash.external.ExternalInterface;
	import flash.system.System;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	public class SharePanel extends Sprite
	{
		private var sharePane:share
		private var myStage:Stage
		private var shape:Sprite
		private var shareBtnArr:Array=[]
			
		private var isShareing:Boolean=false	
			
			
		public var url_1:String=""	
		public var url_2:String=""	
		public var url_3:String=""	
			
		public var text:TextField=new TextField()	
		public var myPlayer:MainFlvPlayer
		public function SharePanel(stage:Stage,player:MainFlvPlayer)
		{
			super();
			this.myStage=stage
			myPlayer=player
			sharePane=new share()
			shape=new Sprite()
			addChild(shape)
			addChild(sharePane)
			
//			sharePane.urltxt.width=200
			
			sharePane.changebtn1.gotoAndStop(1)
			sharePane.changebtn2.gotoAndStop(2)
			sharePane.changebtn3.gotoAndStop(2)
				
//			createShareBtnArr()
			
			this.visible=false
			sharePane.closebtn.addEventListener(MouseEvent.CLICK,doClose)
			sharePane.playback.addEventListener(MouseEvent.CLICK,doClose)
				
			sharePane.changebtn1.addEventListener(MouseEvent.CLICK,doClick_1)
			sharePane.changebtn2.addEventListener(MouseEvent.CLICK,doClick_2)
			sharePane.changebtn3.addEventListener(MouseEvent.CLICK,doClick_3)
			
			sharePane.copybtn.addEventListener(MouseEvent.CLICK,doClick)	
			text.x=40
			text.y=290
			text.height=20
			text.width=sharePane.urltxt.width
			sharePane.addChild(text)	
			
		}
		
		public function doClick(e:MouseEvent):void{
			System.setClipboard(text.text)
		}
		
		public function doClick_1(e:MouseEvent):void{
			changState(e.target as MovieClip)
			sharePane.changebtn2.gotoAndStop(2)
			sharePane.changebtn3.gotoAndStop(2)
			setText(1)
		}
		
		public function doClick_2(e:MouseEvent):void{
			changState(e.target as MovieClip)
			sharePane.changebtn1.gotoAndStop(2)
			sharePane.changebtn3.gotoAndStop(2)
			setText(3)
		}
		
		public function doClick_3(e:MouseEvent):void{
			changState(e.target as MovieClip)
			sharePane.changebtn1.gotoAndStop(2)
			sharePane.changebtn2.gotoAndStop(2)
			setText(2)
		}
		
		public function changState(mc:MovieClip):void{
			if(mc.currentFrame==1){
				mc.gotoAndStop(2)
			}
			if(mc.currentFrame==2){
				mc.gotoAndStop(1)
			}
		}
		
		public function doClose(e:MouseEvent):void{
		   this.visible=false
		   isShareing=true
		   sharePane.x=0
		   sharePane.y=0
		   myPlayer.play()
		}
		
		public function changeXY():void{
			shape.graphics.clear()
				
			myPlayer.pause()
				
			shape.graphics.beginFill(0xffffff,0)
			if(this.myStage.displayState=="normal"){
				shape.graphics.drawRect(0,0,Data.swfWidth,Data.swfHeight)
			}else if(this.myStage.displayState=="fullScreen"){
				shape.graphics.drawRect(0,0,this.myStage.fullScreenWidth,this.myStage.fullScreenHeight)
			}
			shape.graphics.endFill()
				
			sharePane.x=(this.width-sharePane.width)/2
			sharePane.y=(this.height-sharePane.height)/2
			isShareing=true
			this.visible=true
				
			setText()
			if(as3_player.mode==as3_player.SWF_STAGE){
				url_2=parent.loaderInfo.loaderURL
				url_3=parent.loaderInfo.loaderURL.split(".swf")[0]+".html"
			}
			
		}
		
		public function changeWH():void{
			shape.graphics.clear()
			
			shape.graphics.beginFill(0xffffff,0)
			if(this.myStage.displayState=="normal"){
				shape.graphics.drawRect(0,0,Data.swfWidth,Data.swfHeight)
			}else if(this.myStage.displayState=="fullScreen"){
				shape.graphics.drawRect(0,0,this.myStage.fullScreenWidth,this.myStage.fullScreenHeight)
			}
			shape.graphics.endFill()
			sharePane.urltxt.mouseEnabled=true
			sharePane.x=(Data.swfWidth-sharePane.width)/2
			sharePane.y=(Data.swfHeight-sharePane.height)/2
		}
		
		public function setText(mode:int=0):void{
			switch(mode)
			{
				case 1:
					text.text=url_1
					break;
				case 2:
					text.text=url_3
					break;
				case 3:
					text.text=url_2
					break;
					
				default:
					text.text=url_1
					break;
			}
		}
		
		public function createShareBtnArr():void{
			for(var i:int=0;i<16;i++){
//				var shareBtn:ShareBitBtn=new ShareBitBtn(Data.btnBitmapDataArr[0])
				var shareBtn:ShareBitBtn=new ShareBitBtn(Data.btnBitmapDataArr[i],i)
				shareBtnArr.push(shareBtn)
				shareBtn.x=35+i*50
				shareBtn.y=100
				if(i>7)	{
					shareBtn.y=140
					shareBtn.x=35+(i-8)*50
				}
				shareBtn.addEventListener(MouseEvent.CLICK,doShare)
				sharePane.addChild(shareBtn)
			}
		}
		
		public function doShare(e:MouseEvent):void{
			if(ExternalInterface.available) {
				ExternalInterface.call("share",e.target.myIndex);
			}
		}
		
	}
}